package arrayExercise.test3;

public class PhoneTest {
    public static void main(String[] args) {
        //1.创建一个数组
        Phone[] arr = new Phone[3];
        //2.创建手机对象
        Phone p1 = new Phone("华为",3900,"白色");
        Phone p2 = new Phone("小米",2900,"耀黑色");
        Phone p3 = new Phone("魅族",1900,"粉色");
        //3.把手机对象添加到数组当中
        arr[0] = p1;
        arr[1] = p2;
        arr[2] = p3;
        //4.获取三部手机的平均价格
        double sum = 0;
        for (int i = 0; i < arr.length; i++) {
            // 获取数组中的手机对象
            Phone phone = arr[i];
            // 计算总和
            sum += phone.getPrice();
        }

        //5.求平均值
        //数据能不写死就不写死
        double avg = sum/arr.length;

        System.out.println("手机的平均价格为："+avg);

    }
}
